import { _decorator, Color, Component, Label, Node, sys } from "cc";
import { NATIVE } from "cc/env";
const { ccclass, property, menu } = _decorator;

///<reference path="./Demo.d.ts">

@ccclass("HelloNative")
@menu("demo/native-plugin")
export class HelloNative extends Component {
  @property({ type: Label, tooltip: "状态" })
  stateLabel: Label = null!;

  @property(Label)
  resultLabel: Label = null!;

  start() {
    debugger;
    if (NATIVE && typeof Demo === "undefined") {
      this.failTest("失败:class未导出，本地插件是否启用?", "[空]");
    } else if (NATIVE) {
      const d = new Demo("zhansan");
      this.stateLabel.string = "Success:看消息";
      this.resultLabel.string = d.hello("Hello World!");
    } else {
      this.failTest("平台不支持", "[空]");
    }
  }

  update(deltaTime: number) {}

  private failTest(state: string, error: string) {
    this.stateLabel.string = state;
    this.resultLabel.string = error;
    this.stateLabel.color = Color.RED;
  }
}
